package com.itheima.controller;


import com.itheima.pojo.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller   // 声明被扫描
@ResponseBody    // 声明响应体的类 在类上说明 该类下的所有方法返回值都是有响应体的 
@RequestMapping("/book")  // 给路径添加一个前缀名  方便通过改路径查找
public class BookController {

    // 添加
    @PostMapping
    @RequestMapping("/save")
    public String save(@RequestBody Book book) {
        System.out.println("book-save==>>>  " + book);
        return "'info':'book Hello'";
    }

    // 查询全部

    @GetMapping
    @RequestMapping("/getAll")
    public List<Book> getAll() {
        List<Book> list = new ArrayList<Book>();
        list.add(new Book(1,"计算机","入门教程","新手入门 "));
        list.add(new Book(2,"计算机","进阶教程","轻车熟路 "));
        list.add(new Book(3,"计算机","实战教程","稳稳拿捏 "));
        System.out.println("getAll 调用添加成功");
        return list;
    }


    @RequestMapping("/edit")
    @PutMapping
    public String edit(Book book){
        System.out.println("book update ==> "+ book);
        return "{'module':'book update success'}";
    }



}
